package ReflectDemo;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;

/*
    运行配置文件指定内容
 */
public class ReflectDemo9 {
    public static void main(String[] args) throws IOException, NoSuchMethodException, ClassNotFoundException, InvocationTargetException, InstantiationException, IllegalAccessException {
        //加载数据
        Properties prop = new Properties();
        FileReader fileReader = new FileReader("MyInterface\\src\\ReflectDemo\\class.txt");
        prop.load(fileReader);
        fileReader.close();

        String className = prop.getProperty("className");
        String methodName = prop.getProperty("methodName");

        Class<?> aClass = Class.forName(className);
        Constructor<?> con = aClass.getConstructor();
        Object obj = con.newInstance();

        Method method = aClass.getDeclaredMethod(methodName);
        method.setAccessible(true);
        method.invoke(obj);


    }
}
